package com.bazaaroid.server.gae.api.resources;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.bazaaroid.server.gae.core.dao.UserDAO;
import com.bazaaroid.server.gae.core.dto.UserDTO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO.UsersDTO;
import com.bazaaroid.server.gae.core.ioc.GuiceFactory;
import com.bazaaroid.server.gae.core.persistence.model.User;

@Path("/user/")
public class UserResource {

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/{username}")
	public UserDTO getByUsername(@PathParam ("username") String username) {
		UserDAO userDAO = GuiceFactory.getInjector().getInstance(UserDAO.class);
		User user = userDAO.getUserByUsername(username);
		return new UserDTO(user);
	}

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/all/")
	public UsersDTO getAllUsers() {
		UserDAO userDAO = GuiceFactory.getInjector()
			.getInstance(UserDAO.class);
		List<User> users = userDAO.getAll();
		return new AllEntitiesDTO.UsersDTO(users);
	}
}
